<template>
  <!--业务逻辑绑定-->
  <Login :is-user="true" v-model="formdata" @submit="onSubmit"></Login>
</template>

<script>
import Login from "@/components/form/Login.vue";
import userApi from "@/assets/api/user.js";
import { setTimeout } from "timers";

export default {
  components: {
    Login
  },
  data() {
    return {
      formdata: {
        name: "",
        pass: ""
      }
    };
  },
  methods: {
    onSubmit() {
      if (this.formdata.name == null) {
        this.$message({
          message: "请输入用户名",
          type: "warning"
        });
        return;
      }
      if (this.formdata.pass == null) {
        this.$message({
          message: "请输入密码",
          type: "warning"
        });
        return;
      }
      userApi.login(this.formdata).then(res => {
        if (res.data.success == 1) {
          this.$message({
            message: "登录成功",
            type: "success"
          });
          setTimeout(() => {
            location.href = "/";
          }, 1000);
        } else {
          this.$message.error(res.data.message);
          return;
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
